﻿package com.pandemicode.framework.encoding {
	import flash.utils.ByteArray;
	import mx.utils.Base64Decoder;
	import mx.utils.Base64Encoder;
	/**
	 * @author Michael Lawrence
	 */
	public class Base64 {
		private static var _encoder:Base64Encoder = new Base64Encoder();
		private static var _decoder:Base64Decoder = new Base64Decoder();
		
		public function Base64() { }
		
		public static function encode(data:String):String {
			_encoder.reset();
			_encoder.flush();
			_encoder.encode(data);
			return _encoder.toString();
		}
		
		public static function encodeBytes(data:ByteArray):String {
			_encoder.reset();
			_encoder.flush();
			_encoder.encodeBytes(data);
			return _encoder.toString();
		}
		
		public static function encodeUTFBytes(data:String):String {
			_encoder.reset();
			_encoder.flush();
			_encoder.encodeUTFBytes(data);
			return _encoder.toString();
		}
		
		public static function decode(encoded:String):ByteArray {
			_decoder.reset();
			_decoder.flush();
			_decoder.decode(encoded);
			return _decoder.toByteArray();
		}
	}
}